import uuid

from django.contrib.contenttypes.fields import GenericRelation
from django.db import IntegrityError
from django.db import models

from rest_framework.pagination import PageNumberPagination

from apps.system.models import Check
from extensions.models import *

class Pagination(PageNumberPagination):
    page_size = 15
    page_size_query_param = 'page_size'
    page_query_param = 'current'
    max_page_size = 100000

class Personal_Center_Region_Pagination(PageNumberPagination):
    page_size = 9999
    page_size_query_param = 'page_size'
    page_query_param = 'current'
    max_page_size = 100000


class BaseModel(Model):
    """基本类"""
    number = CharField(max_length=256, verbose_name='编号')
    name = CharField(max_length=256, verbose_name='名称')
    contact = CharField(max_length=256, null=True, blank=True, verbose_name='联系人')
    phone = CharField(max_length=256, null=True, blank=True, verbose_name='手机号')
    email = CharField(max_length=256, null=True, blank=True, verbose_name='邮箱')
    remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
    step = IntegerField(verbose_name='填报步骤', null=True, blank=True)
    del_flag = BooleanField(default=False, null=True, blank=True, verbose_name='删除标志')  # 0=未删除1=已删除
    is_effective  = IntegerField(default=0,null=True, blank=True, verbose_name='状态')#状态-1=待修改0=待审核1=已生效
    create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间',null=True, blank=True)
    update_time = DateTimeField(auto_now=True, verbose_name='更新时间',null=True, blank=True)
    last_random_number = 0

    class Meta:
        abstract=True

class InfoBaseModel(Model):
    """Pbi项目信息管理基本类"""
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, null=True, default=None,related_name='%(class)s_company')  # 填报公司
    number = CharField(max_length=256, verbose_name='编号',unique=True)
    name = CharField(max_length=256, verbose_name='名称')
    remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')
    step = IntegerField(verbose_name='填报步骤', null=True, blank=True)
    del_flag = BooleanField(default=False, null=True, blank=True, verbose_name='删除标志')  # 0=未删除1=已删除
    is_effective  = IntegerField(default=0,null=True, blank=True, verbose_name='状态')#状态-1=待修改0=待审核1=已生效
    create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间',null=True, blank=True)
    update_time = DateTimeField(auto_now=True, verbose_name='更新时间',null=True, blank=True)
    creator = ForeignKey('system.User', on_delete=CASCADE, blank=True, null=True, default=None, verbose_name='创建者',related_name='%(class)s_creator')
    updater = ForeignKey('system.User', on_delete=CASCADE, blank=True, null=True, default=None, verbose_name='更新者',related_name='%(class)s_updater')
    next_checker = ForeignKey('system.User', on_delete=CASCADE, blank=True, null=True, default=None,related_name='%(class)s_next_checker')  # 下一步审核或操作的人

    class Meta:
        abstract=True


class Options(Model):
    name = CharField(max_length=255, unique=True, blank=True,verbose_name='该名称')
    add_time =DateTimeField(auto_now_add=True, verbose_name='创建时间',null=True, blank=True)

    class Meta:
        verbose_name = '选项'
        verbose_name_plural = verbose_name
        abstract=True

    def __str__(self):
        return self.name


class GzdeBaseModel(Model):
    name = CharField(max_length=255, unique=True, blank=True, verbose_name='名称')
    del_flag = BooleanField(default=False, null=True, blank=True, verbose_name='删除标志')  # 0=未删除1=已删除
    create_time = DateTimeField(auto_now_add=True, verbose_name='创建时间',null=True, blank=True)
    update_time = DateTimeField(auto_now=True, verbose_name='更新时间',null=True, blank=True)
    creator = ForeignKey('system.User', on_delete=CASCADE, blank=True, null=True, default=None, verbose_name='创建者',related_name='%(class)s_creator',db_constraint=False)
    updater = ForeignKey('system.User', on_delete=CASCADE, blank=True, null=True, default=None, verbose_name='更新者',related_name='%(class)s_updater',db_constraint=False)
    remark = CharField(max_length=256, null=True, blank=True, verbose_name='备注')

    class Meta:
        abstract=True

